/**
 * Created by panjun7@yunzongnet.com
 */
 var suitShopsController = null;
(function(doc, win) {

    // sui 页面就绪时间
    $(doc).on("pageInit", "#suitShopsPage", function() {
        suitShopsController = new SuitShopsController();
        suitShopsController.initPage();
    });


    //选中样式
    $(document).on("click", "#suitShopsPage .list>li", function () {
        $(this).addClass("selected").siblings("li").removeClass("selected");
    });

    //checkbox
    $(document).on("click", "#suitShopsPage .checkbox", function () {
        $(this).toggleClass("checked");
    });

    //同步城市
    $(document).on("click", "#suitShopsPage .store-list .checkbox", function () {
        var isCityAll = true;
        var $this = $(this);
        $this.parents(".page-body").find(".checkbox").each(function () {
            if (!$(this).hasClass("checked")) {
                isCityAll = false;
            }
        });
        if (isCityAll) {
            $("#suitShopsPage .check-all").addClass("checked");
        } else {
            $("#suitShopsPage .check-all").removeClass("checked");
        }
    });

    //全选
    $(doc).on("click","#suitShopsPage .check-all",function(){
    	var isCityAll = $(this).hasClass("checked");
        if (isCityAll) {
            $(".checkbox").not(".check-all").addClass("checked");
        } else {
            $(".checkbox").not(".check-all").removeClass("checked");
        }
    });

    //点击确定按钮
    $(doc).on("click","#suitShopsPage .scroll-view .right",function(){
    	var selectedShopInfo = suitShopsController.getSelectedShopInfo();
        if(selectedShopInfo.suitShops == ''){
            DialogUtil.dialogWarn("请选择适用门店");
            return false;
        }
    	CommonUtil.injectParamObject(selectedShopInfo);

    	$.router.back();
    });
})(document, window);
